package net.asfun.jvalog.action;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.asfun.jvalog.domain.Blog;
import net.asfun.jvalog.http.RequestUtil;
import net.asfun.jvalog.misc.FileUtil;
import net.asfun.jvalog.misc.Setting;

public class IndexAction extends BaseAction {

	public void index(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		this.render("admin/index.html", resp);
	}

	public void infoBlog(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		this.assign("blog", Blog.info());
		String[] themes = FileUtil.listDir(Setting.root + "/themes/");
		this.assign("themes", themes);
		this.render("admin/site.html", resp);
	}

	public void updateBlog(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		Blog site = Blog.info();
		site.setTitle(RequestUtil.getRequiredParam(req, "title"));
		site.setSubtitle(RequestUtil.getRequiredParam(req, "subtitle"));
		site.setKeywords(RequestUtil.getStringParam(req, "keywords"));
		site.setDescription(RequestUtil.getRequiredParam(req, "description"));
		site.setUrl(RequestUtil.getRequiredParam(req, "url"));
		site.setVersion(RequestUtil.getRequiredParam(req, "version"));
		site.update();
		this.tip("blog.update", resp);
	}

	public void test(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		this.render("test.html", resp);
	}

}
